package com.ruoyi.system.service.impl;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

import com.ruoyi.system.constant.Constants;
import com.ruoyi.system.domain.Pens;
import com.ruoyi.system.domain.ScrTotalanduser;
import com.ruoyi.system.domain.UsernameLocation;
import com.ruoyi.system.mapper.PensMapper;
import com.ruoyi.system.mapper.ScaleRecordMapper;
import com.ruoyi.system.mapper.UsernameLocationMapper;
import com.ruoyi.system.service.IPensService;
import com.ruoyi.system.utils.ExcelEditor;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.ScrTotalMapper;
import com.ruoyi.system.domain.ScrTotal;
import com.ruoyi.system.service.IScrTotalService;

/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author ruoyi
 * @date 2024-01-23
 */
@Service
public class ScrTotalServiceImpl implements IScrTotalService
{
    @Autowired
    private PensMapper pensMapper;

    @Autowired
    private UsernameLocationMapper usernameLocationMapper;

    @Autowired
    private ScrTotalMapper scrTotalMapper;

    @Autowired
    private ScaleRecordMapper scaleRecordMapper;

    /**
     * 查询【请填写功能名称】
     *
     * @param id 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public ScrTotal selectScrTotalById(Long id)
    {
        return scrTotalMapper.selectScrTotalById(id);
    }

    /**
     * 查询【请填写功能名称】列表
     *
     * @param scrTotal 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<ScrTotal> selectScrTotalList(ScrTotal scrTotal)
    {
        return scrTotalMapper.selectScrTotalList(scrTotal);
    }


    @Override
    public HashMap<Long, Integer> selectScrTotalListbyuser(ScrTotal scrTotal, String username) {
        List<UsernameLocation> list0 = new ArrayList<>();

        list0 = usernameLocationMapper.selectLocationByUsername(username);
        List<String> locations = new ArrayList<>();
        for(UsernameLocation usernameLocation:list0){
            locations.add(usernameLocation.getLocation());
        }


        List<Pens> pensList = pensMapper.selectPensList(new Pens());
        List<String> penIdlist = new ArrayList<>();


        for(String location:locations){
            for(Pens pens : pensList){
                if(pens.getLocation().equals(location)){
                    penIdlist.add(pens.getPenId());
                }
            }
        }
        HashMap<Long, Integer> idMap = new HashMap<>();
        List<Long> idList = new ArrayList<>();
        for(String penId:penIdlist){
            List<Long> idListtemp =  scaleRecordMapper.selectIdByPenId(penId);
            for(Long l:idListtemp){
                idList.add(l);
            }
            idListtemp = new ArrayList<>();
        }
        //List<Long> idList = scaleRecordMapper.selectIdByPenId(penId);
        for(Long id : idList) idMap.put(id, 1);
        return idMap;



    }


    @Override
    public List<ScrTotalanduser> selectScrTotalanduserList(ScrTotalanduser scrTotalanduser) {
        List<ScrTotalanduser> list = scrTotalMapper.selectScrTotalListanduser(scrTotalanduser);
        List<ScrTotalanduser> list2 = new ArrayList<>();
        for (ScrTotalanduser scrtu:list){
            if(scrtu.getUserInfoId()==-1){
                scrtu.setname("未命名");
                list2.add(scrtu);
            }
            else
                list2.add(scrtu);
        }
        return list2;
    }

    /**
     * 新增【请填写功能名称】
     *
     * @param scrTotal 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertScrTotal(ScrTotal scrTotal)
    {
        return scrTotalMapper.insertScrTotal(scrTotal);
    }




    /**
     * 修改【请填写功能名称】
     *
     * @param scrTotal 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateScrTotal(ScrTotal scrTotal) throws IOException {
        int res = scrTotalMapper.updateScrTotal(scrTotal);
        String pth = Constants.BASE_DIR + "\\" + scrTotal.getId().toString() + "\\" + scrTotal.getId().toString() + ".xlsx";
        System.out.println(pth);
        ExcelEditor excelEditor = new ExcelEditor(pth);
        excelEditor.update(scrTotal);
        return res;
    }

    @Override
    public int updateScrTotalbyscrid(ScrTotal scrTotal) {
        return scrTotalMapper.updateScrTotalbyscrId(scrTotal);
    }

    /**
     * 批量删除【请填写功能名称】
     *
     * @param ids 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteScrTotalByIds(Long[] ids)
    {
        return scrTotalMapper.deleteScrTotalByIds(ids);
    }

    @Override
    public List<Integer> insertScrTotalbymap(Map<String, Double> totalmap, Long scrid,String str, String tim, String penId) {
        ScrTotal scrTotal = new ScrTotal();
        scrTotal.setScrId(scrid);
        BigDecimal score1=new BigDecimal(0);
        BigDecimal score2=new BigDecimal(0);
        for(Map.Entry<String,Double> entry:totalmap.entrySet()){
            if(entry.getKey().equals("NPI1 total")&&entry.getValue()!=null){
                //scrTotal.setNPI1(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score=BigDecimal.valueOf(entry.getValue());
                scrTotal.setNPI1(score);
            }else if(entry.getKey().equals("NPI2 total")&&entry.getValue()!=null){
                //scrTotal.setNPI2(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score=BigDecimal.valueOf(entry.getValue());
                scrTotal.setNPI2(score);
            }else if(entry.getKey().equals("ADL total")&&entry.getValue()!=null){
                //scrTotal.setADL(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score=BigDecimal.valueOf(entry.getValue());
                scrTotal.setADL(score);
                if(score.compareTo(BigDecimal.valueOf(21)) == 0){
                    String level="完全独立";
                    scrTotal.setAdlLevel(level);
                }
                else if (score.compareTo(BigDecimal.valueOf(33)) <= 0) {
                    String level= "基本独立";
                    scrTotal.setAdlLevel(level);
                }
                else if (score.compareTo(BigDecimal.valueOf(46)) <= 0) {
                    String level= "轻度依赖";
                    scrTotal.setAdlLevel(level);
                }
                else if (score.compareTo(BigDecimal.valueOf(58)) <= 0) {
                    String level= "中度依赖";
                    scrTotal.setAdlLevel(level);
                }
                else if (score.compareTo(BigDecimal.valueOf(71)) <= 0) {
                    String level= "重度依赖";
                    scrTotal.setAdlLevel(level);
                }
                else {
                    String level= "完全依赖";
                    scrTotal.setAdlLevel(level);
                }
            } else if(entry.getKey().equals("CDR total")&&entry.getValue()!=null){
                //scrTotal.setCDR(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score=BigDecimal.valueOf(entry.getValue());
                scrTotal.setCDR(score);
                if(score.compareTo(BigDecimal.valueOf(3)) > 0){
                    String level="重度痴呆";
                    scrTotal.setCdrLevel(level);
                }
                else if (score.compareTo(BigDecimal.valueOf(2)) > 0) {
                    String level= "中度痴呆";
                    scrTotal.setCdrLevel(level);
                }
                else if (score.compareTo(BigDecimal.valueOf(1)) > 0) {
                    String level= "轻度痴呆";
                    scrTotal.setCdrLevel(level);
                }
                else if (score.compareTo(BigDecimal.valueOf(0)) > 0) {
                    String level= "可疑痴呆";
                    scrTotal.setCdrLevel(level);
                }
                else {
                    String level= "健康";
                    scrTotal.setCdrLevel(level);
                }
            }else if(entry.getKey().equals("AQD1 total")&&entry.getValue()!=null){
                //scrTotal.setAQD1(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score=BigDecimal.valueOf(entry.getValue());
                scrTotal.setAQD1(score);
            }else if(entry.getKey().equals("MMSE total")&&entry.getValue()!=null){
                BigDecimal score=BigDecimal.valueOf(entry.getValue());
                scrTotal.setMMSE(score);
                if(score.compareTo(BigDecimal.valueOf(27)) >= 0){
                    String level="正常";
                    scrTotal.setMmseLevel(level);
                }
                else if (score.compareTo(BigDecimal.valueOf(24)) >= 0) {
                    String level= "轻度认知障碍";
                    scrTotal.setMmseLevel(level);
                }
                else if (score.compareTo(BigDecimal.valueOf(21)) >= 0) {
                    String level= "中度认知障碍";
                    scrTotal.setMmseLevel(level);
                } else if (score.compareTo(BigDecimal.valueOf(10)) >= 0) {
                    String level= "重度认知障碍";
                    scrTotal.setMmseLevel(level);
                } else {
                    String level= "极重度认知障碍";
                    scrTotal.setMmseLevel(level);
                }
            }else if(entry.getKey().equals("DST1 total")&&entry.getValue()!=null) {
                //scrTotal.setDST1(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setDST1(score);
            }else if(entry.getKey().equals("DST2 total")&&entry.getValue()!=null) {
                //scrTotal.setDST2(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setDST2(score);
            }else if(entry.getKey().equals("TMT1B time")&&entry.getValue()!=null) {
                //scrTotal.setTmt1b(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setTmt1b(score);
            }else if(entry.getKey().equals("TMT2A time")&&entry.getValue()!=null) {
                //scrTotal.setTmt2a(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setTmt2a(score);
            }else if(entry.getKey().equals("TMT2B time")&&entry.getValue()!=null) {
                //scrTotal.setTmt2b(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setTmt2b(score);
            }else if(entry.getKey().equals("HIS total")&&entry.getValue()!=null){
                //scrTotal.setHIS(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score=BigDecimal.valueOf(entry.getValue());
                scrTotal.setHIS(score);
                if(score.compareTo(BigDecimal.valueOf(12)) >= 0){
                    String level="重度血管性痴呆";
                    scrTotal.setHisLevel(level);
                }
                else if (score.compareTo(BigDecimal.valueOf(7)) >= 0) {
                    String level= "血管性痴呆";
                    scrTotal.setHisLevel(level);
                }
                else if (score.compareTo(BigDecimal.valueOf(4)) >= 0) {
                    String level= "可能血管性痴呆";
                    scrTotal.setHisLevel(level);
                }
                else {
                    String level= "老年性痴呆";
                    scrTotal.setHisLevel(level);
                }
            }else if(entry.getKey().equals("GDS total")&&entry.getValue()!=null){
                //scrTotal.setGDS(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score=BigDecimal.valueOf(entry.getValue());
                scrTotal.setGDS(score);
                if(score.compareTo(BigDecimal.valueOf(10)) >= 0){
                    String level="重度抑郁";
                    scrTotal.setGdsLevel(level);
                }
                else if (score.compareTo(BigDecimal.valueOf(5)) >= 0) {
                    String level= "中度抑郁";
                    scrTotal.setGdsLevel(level);
                }
                else if (score.compareTo(BigDecimal.valueOf(4)) >= 0) {
                    String level= "轻度抑郁";
                    scrTotal.setGdsLevel(level);
                }
                else {
                    String level= "无抑郁";
                    scrTotal.setGdsLevel(level);
                }
            }else if(entry.getKey().equals("PSQI total")&&entry.getValue()!=null){
                //scrTotal.setPSQI(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score=BigDecimal.valueOf(entry.getValue());
                scrTotal.setPSQI(score);
                if(score.compareTo(BigDecimal.valueOf(15)) >= 0){
                    String level="睡眠质量很差";
                    scrTotal.setPsqiLevel(level);
                }
                else if (score.compareTo(BigDecimal.valueOf(10)) >= 0) {
                    String level= "睡眠质量一般";
                    scrTotal.setPsqiLevel(level);
                }
                else if (score.compareTo(BigDecimal.valueOf(5)) >= 0) {
                    String level= "睡眠质量还行";
                    scrTotal.setPsqiLevel(level);
                }
                else {
                    String level= "睡眠质量很好";
                    scrTotal.setPsqiLevel(level);
                }
            }else if(entry.getKey().equals("CFT total")&&entry.getValue()!=null) {
                //scrTotal.setCFT(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setCFT(score);
            }else if(entry.getKey().equals("SCDS total")&&entry.getValue()!=null) {
                //scrTotal.setCFT(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setSCDS(score);
            }else if(entry.getKey().equals("AQD2 total")&&entry.getValue()!=null){
                //scrTotal.setAQD2(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score=BigDecimal.valueOf(entry.getValue());
                scrTotal.setAQD2(score);
            }else if(entry.getKey().equals("HAMD total")&&entry.getValue()!=null){
                //scrTotal.setAQD2(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score=BigDecimal.valueOf(entry.getValue());
                scrTotal.setHAMD(score);
            }else if(entry.getKey().equals("HAMA total")&&entry.getValue()!=null){
                //scrTotal.setAQD2(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score=BigDecimal.valueOf(entry.getValue());
                scrTotal.setHAMA(score);
            }else if(entry.getKey().equals("MOCA total")&&entry.getValue()!=null){
                //scrTotal.setMOCA(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score=BigDecimal.valueOf(entry.getValue());
                scrTotal.setMOCA(score);
                if(score.compareTo(BigDecimal.valueOf(26)) >= 0){
                    String level="认知功能正常";
                    scrTotal.setMocaLevel(level);
                }
                else if (score.compareTo(BigDecimal.valueOf(23)) >= 0) {
                    String level= "轻度认知障碍";
                    scrTotal.setMocaLevel(level);
                }
                else if (score.compareTo(BigDecimal.valueOf(17)) >= 0) {
                    String level= "中度认知障碍";
                    scrTotal.setMocaLevel(level);
                }
                else {
                    String level= "重度认知障碍";
                    scrTotal.setMocaLevel(level);
                }
            }else if(entry.getKey().equals("CDT total")&&entry.getValue()!=null) {
                //scrTotal.setCDT(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setCDT(score);
            }else if(entry.getKey().equals("VFTA1 total")&&entry.getValue()!=null) {
                //scrTotal.setVftA1(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setVftA1(score);
            }else if(entry.getKey().equals("VFTA2 total")&&entry.getValue()!=null) {
                //scrTotal.setVftA2(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setVftA2(score);
            }else if(entry.getKey().equals("VFTB1 total")&&entry.getValue()!=null) {
                //scrTotal.setVftB1(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setVftB1(score);
            }else if(entry.getKey().equals("VFTB2 total")&&entry.getValue()!=null) {
                //scrTotal.setVftB2(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setVftB2(score);
            }else if(entry.getKey().equals("VFTC1 total")&&entry.getValue()!=null) {
                //scrTotal.setVftC1(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setVftC1(score);
            }else if(entry.getKey().equals("VFTC2 total")&&entry.getValue()!=null) {
                //scrTotal.setVftC2(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setVftC2(score);
            }else if(entry.getKey().equals("MMSE-directive")&&entry.getValue()!=null) {
                //scrTotal.setVftC2(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setMmseDirective(score);
            }else if(entry.getKey().equals("MMSE-memory")&&entry.getValue()!=null) {
                //scrTotal.setVftC2(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setMmseMemory(score);
            }else if(entry.getKey().equals("MMSE-attention")&&entry.getValue()!=null) {
                //scrTotal.setVftC2(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setMmseAttention(score);
            }else if(entry.getKey().equals("MMSE-recall")&&entry.getValue()!=null) {
                //scrTotal.setVftC2(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setMmseRecall(score);
            }else if(entry.getKey().equals("MMSE-language")&&entry.getValue()!=null) {
                //scrTotal.setVftC2(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setMmseLanguage(score);
            }else if(entry.getKey().equals("MOCA1 total")&&entry.getValue()!=null) {
                //scrTotal.setVftC2(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setMOCA1(score);
            }else if(entry.getKey().equals("MOCA2 total")&&entry.getValue()!=null) {
                //scrTotal.setVftC2(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setMOCA2(score);
            }else if(entry.getKey().equals("MOCA2 total")&&entry.getValue()!=null) {
                //scrTotal.setVftC2(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setMOCA3(score);
            }else if(entry.getKey().equals("MOCA4 total")&&entry.getValue()!=null) {
                //scrTotal.setVftC2(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setMOCA4(score);
            }else if(entry.getKey().equals("MOCA5 total")&&entry.getValue()!=null) {
                //scrTotal.setVftC2(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setMOCA5(score);
            }else if(entry.getKey().equals("MOCA6 total")&&entry.getValue()!=null) {
                //scrTotal.setVftC2(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setMOCA6(score);
            }else if(entry.getKey().equals("MOCA7 total")&&entry.getValue()!=null) {
                //scrTotal.setVftC2(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setMOCA7(score);
            }else if(entry.getKey().equals("MOCA8 total")&&entry.getValue()!=null) {
                //scrTotal.setVftC2(BigDecimal.valueOf(entry.getValue()));
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setMOCA8(score);
            }else if(entry.getKey().equals("AVLT-N1 total")&&entry.getValue()!=null){
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setAvltN1(score);
            }else if(entry.getKey().equals("AVLT-N1 total")&&entry.getValue()!=null){
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setAvltN1(score);
            }else if(entry.getKey().equals("AVLT-N2 total")&&entry.getValue()!=null){
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setAvltN2(score);
            }else if(entry.getKey().equals("AVLT-N3 total")&&entry.getValue()!=null){
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setAvltN3(score);
            }else if(entry.getKey().equals("AVLT-N4 total")&&entry.getValue()!=null){
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setAvltN4(score);
            }else if(entry.getKey().equals("AVLT-N5 total")&&entry.getValue()!=null){
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setAvltN5(score);
            }else if(entry.getKey().equals("AVLT-N6 total")&&entry.getValue()!=null){
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setAvltN6(score);
            }else if(entry.getKey().equals("AVLT-N7 total")&&entry.getValue()!=null){
                BigDecimal score = BigDecimal.valueOf(entry.getValue());
                scrTotal.setAvltN7(score);
            }

        }
        List<Integer> pageList = Arrays.stream(str.split("\\s+"))
                .map(Integer::parseInt)
                .sorted()
                .collect(Collectors.toList());
        if(pageList.size()==34)
            scrTotal.setStatus(1l);
        else
            scrTotal.setStatus(0l);
        scrTotal.setUserInfoId(-1l);
        scrTotal.setUserInfoId(scrid);
        scrTotal.setDate(tim);
        System.out.println(penId);
        Pens pens = pensMapper.selectPensByPenId(penId);
        try {
            scrTotal.setLocation(pens.getLocation());
        } catch(Exception e){
            System.out.println("No such id");
        }
        scrTotalMapper.insertScrTotal(scrTotal);


        return pageList;
    }

    /**
     * 删除【请填写功能名称】信息
     *
     * @param id 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteScrTotalById(Long id)
    {
        return scrTotalMapper.deleteScrTotalById(id);
    }

    @Override
    public List<ScrTotal> selectScrTotalListByUsername(String username){
        List<UsernameLocation> list0 = new ArrayList<>();
/*        if(username.equals("admin")){
            list0 = usernameLocationMapper.selectallLocation();
        }
        else*/
        list0 = usernameLocationMapper.selectLocationByUsername(username);
        List<String> locations = new ArrayList<>();
        for(UsernameLocation usernameLocation:list0){
            locations.add(usernameLocation.getLocation());
        }
        //List<String> location = list0.get(0).getLocation();

        List<Pens> pensList = pensMapper.selectPensList(new Pens());
        List<String> penIdlist = new ArrayList<>();
        //String penId = "";

/*        for(Pens pens : pensList){
            if(pens.getLocation().equals(location)){
                penId = pens.getPenId();
            }
        }*/

        for(String location:locations){
            for(Pens pens : pensList){
                if(pens.getLocation().equals(location)){
                    penIdlist.add(pens.getPenId());
                }
            }
        }
        HashMap<Long, Integer> idMap = new HashMap<>();
        List<Long> idList = new ArrayList<>();
        for(String penId:penIdlist){
            List<Long> idListtemp =  scaleRecordMapper.selectIdByPenId(penId);
            for(Long l:idListtemp){
                idList.add(l);
            }
            idListtemp = new ArrayList<>();
        }
        //List<Long> idList = scaleRecordMapper.selectIdByPenId(penId);
        for(Long id : idList) idMap.put(id, 1);
        List<ScrTotal> scrTotalList = scrTotalMapper.selectScrTotalList(new ScrTotal());
        List<ScrTotal> retList = new ArrayList<>();
        for(ScrTotal scrTotal : scrTotalList){
            if(idMap.containsKey(scrTotal.getScrId())){
                retList.add(scrTotal);
            }
        }
        return retList;
    }
}
